package com.ykzhujiang.lovespirit.parser;

import java.util.Calendar;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import com.ykzhujiang.lovespirit.entity.Notice;
import com.ykzhujiang.lovespirit.util.Utility;

public class ZhejiangParser extends Parser {

	public ZhejiangParser()
	{	
		resource_root="";
		resource_pattern="(http:\\/\\/bbs\\.zju\\.edu\\.cn\\/cgi-bin\\/showfile?name=[\\S]+?\\.\\w{1,4})(?=')";
		writer_pattern="(?<=发信人: )(.+)(?=,)";
		title_pattern="(?<=标  题: )(.+)(?=\\r\\n)";
		board_pattern="(?<=信区: )(.+)(?=\\r\\n)";
		site_pattern="(?<=发信站: )(.+)(?= \\()";
		content_pattern = "(?<= \\d{4}\\)(.{1,8})?\\r\\n)((?s).*?)(?=(※ 来源:.*?浙江大学海纳百川站)|(※ 修改:.)|\\z)";
		date_pattern = "(?<=\\()((\\w{3}) (\\w{3}) {1,2}(\\w{1,2}) (\\d{2}):(\\d{2}):(\\d{2}) (\\d{4}))(?=\\)(.{1,8})?\\r\\n)";		
		notice_pattern="(?<=<pre>)((?s).*?)(?=<\\/pre>)";
		
	}
	
	public int ParseDate(String text, Notice notice) {
		Pattern p = Pattern.compile(date_pattern);
		Matcher m = p.matcher(text);
		int year, month, date, hour, min, sec;
		if (m.find()) {
			year = Integer.parseInt(m.group(8));
			month = Utility.GetMonth(m.group(3));
			date = Integer.parseInt(m.group(4));
			hour = Integer.parseInt(m.group(5));
			min = Integer.parseInt(m.group(6));
			sec = Integer.parseInt(m.group(7));
//			notice.getCalDate().set(year, month, date, hour, min, sec);
			Calendar c=notice.getCalDate();
			c.set(year, month, date, hour, min, sec);
			notice.setCalDate(c);
		}
		return 0;
	}
}
